package com.zhouyu.starter;

import com.zhouyu.config.AppConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @author leimingchao
 * create 2025-05-25 14:11
 *
 * SpringMvc零xml配置通过这种方式实现
 */
public class MyWebApplicationInitializer implements WebApplicationInitializer {
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {

		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
		applicationContext.register(AppConfig.class);


		DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);

		ServletRegistration.Dynamic registration = servletContext.addServlet("tuling", dispatcherServlet);

		registration.setLoadOnStartup(1);

		registration.addMapping("/tuling/*");
	}
}
